/**
 * 
 */
package com.great.meal.search.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author lenovo
 *
 */
@Entity
@Table(name="t_order")
public class Order implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4063783929188952289L;
	private Long orderId;
	private Customer orderCustomer;
	private Integer customerNum;
	private Hotel hotel;
	private Date time;
	private String location;
	private DishMenu orderMenu;
	private String Other;
	private Sender sender; //送餐人
	private Status status;  //status为true表示订单已成功.false表示订单正在进行状态.
	
	public static enum Status{
		complete, order, send  //完成/订单/已发送订单
	}
	@Override
	public int hashCode() {
		int result = orderId != null ? orderId.hashCode() : 0;
		result = 31 * result + (orderCustomer != null ? orderCustomer.hashCode() : 0);
		result = 31 * result + (customerNum != null ? customerNum.hashCode() : 0);
		result = 31 * result + (hotel != null ? hotel.hashCode() : 0);
		result = 31 * result + (time != null ? time.hashCode() : 0);
		result = 31 * result + (location != null ? location.hashCode() : 0);
		result = 31 * result + (orderMenu != null ? orderMenu.hashCode() : 0);
		result = 31 * result + (Other != null ? Other.hashCode() : 0);
		result = 31 * result + (sender != null ? sender.hashCode() : 0);
		result = 31 * result + (status != null ? status.hashCode() : 0);
		
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(!(obj instanceof Order)) return false;
		
		final Order order = (Order)obj;
		if(!(order.getOrderId().equals(order.getOrderId()))) return false;
		if(!(order.getOrderCustomer().equals(order.getOrderCustomer()))) return false;
		if(!(order.getCustomerNum().equals(order.getCustomerNum()))) return false;
		if(!(order.getHotel().equals(order.getHotel()))) return false;
		if(!(order.getTime().equals(order.getTime()))) return false;
		if(!(order.getLocation().equals(order.getLocation()))) return false;
		if(!(order.getOrderMenu().equals(order.getOrderMenu()))) return false;
		if(!(order.getOther().equals(order.getOther()))) return false;
		if(!(order.getStatus().equals(order.getStatus()))) return false;
		if(!(order.getSender().equals(getSender()))) return false;
		
		return true;
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getOrderId() {
		return orderId;
	}
	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
	
	@OneToOne
	@JoinColumn(name="customerId")
	public Customer getOrderCustomer() {
		return orderCustomer;
	}
	public void setOrderCustomer(Customer orderCustomer) {
		this.orderCustomer = orderCustomer;
	}
	
	public Integer getCustomerNum() {
		return customerNum;
	}
	public void setCustomerNum(Integer customerNum) {
		this.customerNum = customerNum;
	}
	
	@OneToOne
	@JoinColumn(name="hotelId")
	public Hotel getHotel() {
		return hotel;
	}
	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="orderTime")
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	
	@OneToOne
	@JoinColumn(name="dishMenuId")
	public DishMenu getOrderMenu() {
		return orderMenu;
	}
	public void setOrderMenu(DishMenu orderMenu) {
		this.orderMenu = orderMenu;
	}
	
	public String getOther() {
		return Other;
	}
	public void setOther(String other) {
		Other = other;
	}
	
	@OneToOne
	@JoinColumn(name="senderId")
	public Sender getSender() {
		return sender;
	}
	public void setSender(Sender sender) {
		this.sender = sender;
	}
	
	@Enumerated(EnumType.STRING)
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	
	
}
